import json
from thrift import Thrift
from thrift.transport import TSocket, TTransport
from thrift.protocol import TBinaryProtocol
from DONGZHOU.Device.Server import ActionProvider
from DONGZHOU.Device.Server.ttypes import *

class DZinitial:
    def __init__(self, host="127.0.0.1", port=9300):
        self.host = host
        self.port = port
        self.transport = TSocket.TSocket(self.host, self.port)
        self.transport = TTransport.TBufferedTransport(self.transport)
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.client = ActionProvider.Client(self.protocol)
        self.transport.open()

    def close(self):
        if self.transport and self.transport.isOpen():
            self.transport.close()

    def get_name(self):
        return self.client.GetName()

    def get_devices(self):
        return self.client.GetDevices()

    def sound_record(self):
        """
        利用麦克风录制声音

        """
        pass
